package com.ruoyi.blog.controller.api;

import com.ruoyi.blog.domain.BlogType;
import com.ruoyi.blog.domain.vo.ResultArticleListVo;
import com.ruoyi.blog.service.IBlogArticleService;
import com.ruoyi.blog.service.impl.BlogTypeServiceImpl;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/blog/classify")
public class ClassifyController extends BaseController {

    @Autowired
    private BlogTypeServiceImpl blogTypeService;

    @Autowired
    private IBlogArticleService iBlogArticleService;

    /**
     * 查询分类列表
     * @return
     */
    @GetMapping("/getClassifyList")
    public AjaxResult getClassifyList() {
        List<BlogType> list = blogTypeService.getTreeTypeList();
        return AjaxResult.success(list);
    }

    /**
     * 根据分类查询文章列表及数据
     * @param typeName
     * @return
     */
    @GetMapping("/getClassifyData/{typeName}")
    public AjaxResult getClassifyData(@PathVariable String typeName) {
        Map<String, Object> result = new HashMap<>();
        BlogType blogType = blogTypeService.getTypeInfoByName(typeName);

        startPage();
        List<ResultArticleListVo> list = iBlogArticleService.getArticleListByTypeName(typeName);
        result.put("info",blogType);
        result.put("list", list);
        return AjaxResult.success(result);
    }


}
